local skel = fk.CreateSkill {
  name = "emo__moejie",
}

Fk:loadTranslationTable{
  ["emo__moejie"] = "魔戒",
  [":emo__moejie"] = "游戏开始时，你可以令一名异性角色获得“魔戒”标记，其的准备阶段你可发动“诱惑”，每当你获得其的牌后，令其回复一点体力。",

  ["#emo__moejie-choose"] = "魔戒：你可以令一名异性角色获得“魔戒”标记",
  ["@@emo__moejie"] = "魔戒",
  ["#emo__moejie-invoke"] = "魔戒：你可以令 %src 摸一张牌",
}

skel:addEffect(fk.GameStart, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and table.find(player.room:getOtherPlayers(player, false), function (p)
      return p.gender ~= player.gender
    end)
  end,
  on_cost = function (self, event, target, player, data)
    local targets = table.filter(player.room:getOtherPlayers(player, false), function (p) return p.gender ~= player.gender end)
    local tos = player.room:askToChoosePlayers(player, {
      min_num = 1, max_num = 1, targets = targets, skill_name = skel.name, prompt = "#emo__moejie-choose"
    })
    if #tos > 0 then
      player.room:sortByAction(tos)
      event:setCostData(self, {tos = tos})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    room:addTableMark(to, "@@emo__moejie", player.id)
  end
})

skel:addEffect(fk.AfterCardsMove, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(skel.name) then return false end
    local tos = {}
    for _, move in ipairs(data) do
      if move.from and move.to == player and move.toArea == Player.Hand
      and table.contains(move.from:getTableMark("@@emo__moejie"), player.id)
      and table.find(move.moveInfo, function (info)
        return info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip
      end) then
        table.insertIfNeed(tos, move.from)
      end
    end
    if #tos > 0 then
      player.room:sortByAction(tos)
      event:setCostData(self, {tos = tos })
      return true
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, to in ipairs(event:getCostData(self).tos) do
      if not to.dead then
        room:recover { num = 1, skillName = skel.name, who = to, recoverBy = player }
      end
    end
  end,
})

return skel
